﻿Imports System.ComponentModel
Imports System.Collections.ObjectModel
Imports FuncClasses
Imports System.Threading.Tasks
Imports System.Windows.Threading

Public Class VariousSettingsViewModel
    Implements INotifyPropertyChanged

    Private _dispatcher As Windows.Threading.Dispatcher
    Private _loader As IDatabase

    Private _articleunits As ObservableCollection(Of Unit)
    Private _paymentmethodes As ObservableCollection(Of PaymentMethode)
    Private _ordertexts As ObservableCollection(Of nHibernate.Models.OrderTextModel)
    Private _taxclasses As ObservableCollection(Of TaxClass)

    Public Sub New(loader As IDatabase, dispatcher As Windows.Threading.Dispatcher)
        _loader = loader
        _dispatcher = dispatcher
        'Dim t As task = Task.Factory.StartNew(AddressOf Loading)
        Loading()
    End Sub

    Private Sub Loading()
        _articleunits = _loader.ListOfUnits
        NotifyPropertyChanged("ArticleUnits")

        _paymentmethodes = _loader.ListOfPaymentMethodes
        NotifyPropertyChanged("PaymentMethodes")

        _ordertexts = _loader.ListOfOrderTexts
        NotifyPropertyChanged("OrderTexts")

        _taxclasses = _loader.ListOfTaxes
        NotifyPropertyChanged("TaxClasses")
    End Sub

    Public Property ArticleUnits As ObservableCollection(Of Unit)
        Get
            Return _articleunits
        End Get
        Set(value As ObservableCollection(Of Unit))
            _articleunits = value
            NotifyPropertyChanged("ArticleUnits")
        End Set
    End Property

    Public Property PaymentMethodes As ObservableCollection(Of PaymentMethode)
        Get
            Return _paymentmethodes
        End Get
        Set(value As ObservableCollection(Of PaymentMethode))
            _paymentmethodes = value
            NotifyPropertyChanged("PaymentMethodes")
        End Set
    End Property

    Public Property TaxClasses As ObservableCollection(Of TaxClass)
        Get
            Return _taxclasses
        End Get
        Set(value As ObservableCollection(Of TaxClass))
            _taxclasses = value
            NotifyPropertyChanged("TaxClasses")
        End Set
    End Property

    Public Property OrderTexts As ObservableCollection(Of nHibernate.Models.OrderTextModel)
        Get
            Return _ordertexts
        End Get
        Set(value As ObservableCollection(Of nHibernate.Models.OrderTextModel))
            _ordertexts = value
            NotifyPropertyChanged("OrderTexts")
        End Set
    End Property

    Public ReadOnly Property Currency As Currency
        Get
            Return FuncClasses.Currency.EUR
        End Get
    End Property

    Public Property Database As IDatabase
        Get
            Return _loader
        End Get
        Set(value As IDatabase)
            _loader = value
        End Set
    End Property

    Public Sub Refresh()
        'Dim t As task = Task.Factory.StartNew(AddressOf Loading)
        Loading()
    End Sub

    Protected Sub NotifyPropertyChanged(info As [String])
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub

    Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
